package easyexcel.listener;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * describe:
 *
 * @author huxingjie
 * @date 2019/09/29
 * @since 4.0
 */
@Slf4j
public class CustomStringIntegerConverter implements Converter<Integer> {
    Map<String, Integer> map = Maps.newHashMap();

    public CustomStringIntegerConverter() {
//protocolType
        map.put("TCP", 0);
        map.put("UDP", 1);
        map.put("TCP SERVER", 2);
//ExcelGB28181ViperVo.sipPlayBack
        map.put("实时", 1);
        map.put("回放", 2);
//ExcelGB28181ViperVo.parental
        map.put("否", 0);
        map.put("是", 1);
//ExcelGB28181ViperVo.safetyWay
        map.put("不采用", 0);
        map.put("S/MIME签名方式", 2);
        map.put("S/MIME加密签名同时采用方式", 3);
        map.put("数字摘要方式", 4);
//ExcelGB28181ViperVo.registerWay
        map.put("IETF RFC 3261标准", 1);
        map.put("基于口令的双向认证", 2);
        map.put("基于数字证书的双向认证", 3);
//ExcelGB28181ViperVo.certifiable
        map.put("无效", 0);
        map.put("有效", 1);
//ExcelGB28181ViperVo.secrecy
        map.put("不涉密", 0);
        map.put("涉密", 1);
//ExcelGB28181ViperVo.ptzType
        map.put("球机", 1);
        map.put("半球", 2);
        map.put("固定枪机", 3);
        map.put("遥控枪机", 4);
//ExcelGB28181ViperVo.positionType
        map.put("省际检查站", 1);
        map.put("交通干线", 10);
        map.put("党政机关", 2);
        map.put("车站码头", 3);
        map.put("中心广场", 4);
        map.put("体育馆", 5);
        map.put("商业中心", 6);
        map.put("宗教场所", 7);
        map.put("校园周边", 8);
        map.put("治安复杂区域", 9);
//ExcelGB28181ViperVo.roomType
        map.put("室外", 1);
        map.put("室内", 2);
//ExcelGB28181ViperVo.useType
        map.put("治安", 1);
        map.put("交通", 2);
        map.put("重点", 3);
//ExcelGB28181ViperVo.supplyLightType
        map.put("无补光", 1);
        map.put("红外补光", 2);
        map.put("白光补光", 3);
//ExcelGB28181ViperVo.directionType
        map.put("东", 1);
        map.put("西", 2);
        map.put("南", 3);
        map.put("北", 4);
        map.put("东南", 5);
        map.put("东北", 6);
        map.put("西南", 7);
        map.put("西北", 8);
//ExcelGB28181ViperVo.svcSpaceSupportMode
        map.put("不支持", 0);
        map.put("1级增强", 1);
        map.put("2级增强", 2);
        map.put("3级增强", 3);
//ExcelGB28181ViperVo.svcTimeSupportMode
        map.put("不支持", 0);
        map.put("1级增强", 1);
        map.put("2级增强", 2);
        map.put("3级增强", 3);
    }

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String value = cellData.getStringValue();
        if (StringUtils.isNotBlank(value) && map.containsKey(value)) {
            return map.get(value);
        } else {
            log.error("setCellValueToBeanProperty setField exception, field:" + contentProperty.getHead().getFieldName() + ", object:");
            return null;
        }
    }

    @Override
    public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }
}

    